package com.zhuoya.healthcard;

import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import java.util.Locale;


public class PrintSuccessActivity extends AppCompatActivity {


    private Boolean A;
    private TextView mTimeCount;
    private CountDownTimer timer;

    public PrintSuccessActivity() {
        this.A = true;
    }

    private void startCount() {
        this.timer = new CountDownTimer(10000L, 1000L) {
            public void onFinish() {
                PrintSuccessActivity.this.startActivity(new Intent(PrintSuccessActivity.this, MainActivity.class));
                PrintSuccessActivity.this.finish();
            }

            public void onTick(final long n) {
                PrintSuccessActivity.this.mTimeCount.setText((CharSequence) String.format(Locale.CHINA, "%ds", n / 1000L));
            }
        }.start();
    }

    @Override
    protected void onCreate(final Bundle bundle) {
        super.onCreate(bundle);
        this.setContentView(R.layout.activity_print_success);
        this.mTimeCount = this.findViewById(R.id.timeCount);
        this.startCount();
        this.findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
            public void onClick(final View view) {
                try {
                    PrintSuccessActivity.this.startActivity(new Intent(PrintSuccessActivity.this, MainActivity.class));
                    PrintSuccessActivity.this.finish();
                } catch (Exception ex) {
                }
            }
        });
        this.findViewById(R.id.backTV).setOnClickListener(new View.OnClickListener() {
            public void onClick(final View view) {
                try {
                    PrintSuccessActivity.this.startActivity(new Intent(PrintSuccessActivity.this, MainActivity.class));
                    PrintSuccessActivity.this.finish();
                } catch (Exception ex) {
                }
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        this.A = false;
        final CountDownTimer timer = this.timer;
        if (timer != null) {
            timer.cancel();
        }
    }
}
